<?php
/* -------------------------------------------------------------------------------------
* 	ID:						imageprocessing.php
* 	Letzter Stand:			3
* 	zuletzt geaendert von:	siekiera
* 	Datum:					29.03.2011
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');

function formatBytes($bytes, $precision = 2) {
    $units = array('B', 'KB', 'MB', 'GB', 'TB');

    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);

    $bytes /= pow(1024, $pow);

    return round($bytes, $precision) . ' ' . $units[$pow];
}

require(DIR_FS_ADMIN.DIR_WS_INCLUDES.'xajax/xajax.imageprocessing.php');

require(DIR_WS_INCLUDES.'metatag.php');

$xajax->printJavascript();

if ($dir = opendir(DIR_FS_CATALOG_ORIGINAL_IMAGES)) {
	$p_files = array();
	$size = '';
	while($p_file = readdir($dir))
		if(is_file(DIR_FS_CATALOG_ORIGINAL_IMAGES.$p_file) && ($p_file !="index.html") && (strtolower($p_file) != "thumbs.db") && ($p_file != '.') && ($p_file != '..')) {
			$p_size += filesize(DIR_FS_CATALOG_ORIGINAL_IMAGES.$p_file);
			$p_files[] = array('name' => $p_file, 'size' => filesize(DIR_FS_CATALOG_ORIGINAL_IMAGES.$p_file));
		}
	closedir($dir);
}

if($dir = opendir(DIR_FS_CATALOG_IMAGES.'categories_org/')) {
	$c_files = array();
	$c_size = '';
	while($c_file = readdir($dir))
		if(is_file(DIR_FS_CATALOG_IMAGES.'categories_org/'.$c_file) && ($c_file !="index.html") && (strtolower($c_file) != "thumbs.db") && ($c_file != '.') && ($c_file != '..')) {
			$c_size += filesize(DIR_FS_CATALOG_IMAGES.'categories_org/'.$p_file);
			$c_files[] = array('name' => $c_file);
		}
	closedir($dir);
}
?>
<style type="text/css">
	.process_wrapper {width: 300px; height: 30px;  display:block; text-align: left;}
	.process_inner_wrapper {width: 260px; height: 30px; background: url(../mercari_img.php?h=30px&c1=efefef&c2=cccccc) center left repeat-x; display:block; text-align: left;-moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; float:left; box-shadow: 0 2px 5px #BBBBBB;-moz-box-shadow: 0 2px 5px #BBBBBB; -webkit-box-shadow: 0 2px 5px #BBBBBB;}
	#show_products_process, #show_category_process {width: 0; height: 30px; background: url(../mercari_img.php?h=30px&c1=9DD308&c2=6E9305) center left repeat-x; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;}
	#products_precents, #category_precents {padding: 5px 0 0 0; margin-left: 270px; font-weight: 700}
	.fs85 {font-size: 85%}
	.fwb {font-weight: 700}
	h2 {font-size: 120%; font-weight: 700}
	.table_border {border: 1px solid #ccc; width: 100%}
	.dn {display:none}
	.msg_error_bg {background: url(../mercari_img.php?h=120px&c1=E80000&c2=B70101) center left repeat-x; color: #fff;-moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;padding: 6px}
	#deleted_image {max-height: 200px;overflow: auto;border: 1px solid #CCC;padding: 5px;}
</style>
<script type="text/javascript">
	$(function(){
		$('.start_process').click(function(){
			$('#deleted_image').html('');
		});
	});
</script>
</head>
<body>
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<div id="wrapper">
	<table class="outerTable" cellspacing="0" cellpadding="0">
		<tr>
			<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
				<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
			</td>
			<td class="boxCenter" height="100%" valign="top">
	        	<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
		   			<tr>
		     			<td class="pageHeading">Image Processing mittels Ajax <?php echo get_help('2','Ajax-Imageprocessing'); ?></td>
					</tr>
				</table>
	        	Mit diesem Tool können Sie für bereits erstellte Grafiken die voreingestellten <a href="<?php echo href_link('configuration.php', 'gID=4'); ?>">Bildoptionen</a> für Produkt- und Kategoriebilder anwenden.<br /><br />
	        	Zum Starten auf den Button "Bilder jetzt umrechnen" klicken und einen Moment warten, bis die Ajax-Funktion auf dem Server intialisiert wurde. Sobald der Prozess begonnen hat, kann dieser nur noch mittels ESC - Taste abgebrochen werden.<br /><br />

				<?php if(sizeof($p_files) > 0) { ?>
	        	<table cellpadding="10" class="table_border">
	        		<tr>
	        			<td colspan="2"><h2>Produktbilder</h2></td>
	        		</tr>
	        		<tr>
	        			<td colspan="2"><div id="ajax_product_msg_td" class="dn msg_error_bg"></div></td>
	        		</tr>
	        		<tr>
	        			<td width="1">
	        				<div class="process_wrapper">
				        		<div class="process_inner_wrapper">
				        			<div id="show_products_process"></div>
				        		</div>
				        		<div id="products_precents">0%</div>
				        	</div>
	        			</td>
	        			<td>
	        				<select id="get_type" name="get_type">
	        					<option value="all" selected>alle Bilder neu berechnen</option>
	        					<option value="rest">nur fehlende Bilder berechnen</option>
	        				</select><br /><br/>
	        				<select id="get_name" name="get_name">
	        					<option value="p_name" selected>Bildname = Produktname</option>
	        					<option value="p_id">Bildname = Produkt-ID</option>
	        				</select><br /><br/>
	        				<a href="javascript:void(0)" onclick="xajax_setProductImages(document.getElementById('get_type').value, document.getElementById('get_name').value);" class="button start_process">Produktbilder umrechnen</a> <em class="fs85">zum Abbrechen ESC - Taste drücken</em>
	        			</td>
	        		</tr>
	        		<tr>
	        			<td colspan="2">Bild <span id="products_img_nr" class="fwb">0</span> von insgesamt <b><?php echo sizeof($p_files); ?></b> verarbeitet.</td>
	        		</tr>
	        		<tr>
	        			<td colspan="2">Bildname: <span id="products_img_name_old" class="fwb"><em>alt</em></span> => <span id="products_img_name_new" class="fwb"><em>neu</em></span></td>
	        		</tr>
	        		<tr>
	        			<td colspan="2">Die Datenmenge im original_images - Ordner beträgt <?php echo formatBytes($p_size); ?></td>
	        		</tr>
	        		<tr>
	        			<td colspan="2">gelöschte verwaiste Grafiken:<div id="deleted_image"></div></td>
	        		</tr>
	        	</table>

	        	<?php
				}
	        	if(sizeof($c_files) > 0) { ?>
	        	<br /><br />
	        	<table cellpadding="10" class="table_border">
	        		<tr>
	        			<td colspan="2"><h2>Kategoriebilder</h2></td>
	        		</tr>
	        		<tr>
	        			<td width="1">
	        				<div class="process_wrapper">
				        		<div class="process_inner_wrapper">
				        			<div id="show_category_process"></div>
				        		</div>
				        		<div id="category_precents">0%</div>
				        	</div>
	        			</td>
	        			<td>
	        				<a href="javascript:void(0)" onclick="xajax_setCategoryImages();" class="button">Kategoriebilder umrechnen</a> <em class="fs85">zum Abbrechen ESC - Taste drücken</em>
	        			</td>
	        		</tr>
	        		<tr>
	        			<td colspan="2">Bild <span id="category_img_nr" class="fwb">0</span> von insgesamt <?php echo sizeof($c_files); ?> verarbeitet.</td>
	        		</tr>
	        		<tr>
	        			<td colspan="2">Bildname <span id="category_img_name" class="fwb"><em>leer</em></span></td>
	        		</tr>
	        		<tr>
	        			<td colspan="2">Die Datenmenge im categories_org - Ordner beträgt <?php echo formatBytes($c_size); ?></td>
	        		</tr>
	        	</table>
	        	<?php } ?>

		    </td>
		</tr>
	</table>
</div>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>